MAXREFDES82# Code Documentation  V01.00
Maxim Smart Force Sensor
 All Files Functions Variables Macros Groups Pages
stm32f4xx_hal_msp.c
Go to the documentation of this file.
1 
38 /* Includes ------------------------------------------------------------------*/
39 #include "stm32f4xx_hal.h"
40 //#include "stm324x9i_eval.h"
41 #include "main.h"
42 
52 /* Private typedef -----------------------------------------------------------*/
53 /* Private define ------------------------------------------------------------*/
54 /* Private macro -------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
56 /* Private function prototypes -----------------------------------------------*/
57 /* Private functions ---------------------------------------------------------*/
58 
68 void HAL_UART_MspInit(UART_HandleTypeDef *huart)
69 {
70  static DMA_HandleTypeDef hdma_tx;
71  GPIO_InitTypeDef GPIO_InitStruct;
72 
73  /*##-1- Enable peripherals and GPIO Clocks #################################*/
74  /* Enable GPIO clock */
75  USARTx_TX_GPIO_CLK_ENABLE();
76  USARTx_RX_GPIO_CLK_ENABLE();
77  /* Enable USARTx clock */
78  USARTx_CLK_ENABLE();
79  /* Enable DMAx clock */
80  DMAx_CLK_ENABLE();
81 
82  /*##-2- Configure peripheral GPIO ##########################################*/
83  /* UART TX GPIO pin configuration */
84  GPIO_InitStruct.Pin = USARTx_TX_PIN;
85  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
86  GPIO_InitStruct.Pull = GPIO_PULLUP;
87  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
88  GPIO_InitStruct.Alternate = USARTx_TX_AF;
89 
90  HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
91 
92  /* UART RX GPIO pin configuration */
93  GPIO_InitStruct.Pin = USARTx_RX_PIN;
94  GPIO_InitStruct.Alternate = USARTx_RX_AF;
95 
96  HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
97 
98  /*##-3- Configure the NVIC for UART ########################################*/
99  HAL_NVIC_SetPriority(USARTx_IRQn, 5, 0);
100  HAL_NVIC_EnableIRQ(USARTx_IRQn);
101 
102  /*##-4- Configure the DMA streams ##########################################*/
103  /* Configure the DMA handler for Transmission process */
104  hdma_tx.Instance = USARTx_TX_DMA_STREAM;
105 
106  hdma_tx.Init.Channel = USARTx_TX_DMA_CHANNEL;
107  hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
108  hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
109  hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
110  hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
111  hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
112  hdma_tx.Init.Mode = DMA_NORMAL;
113  hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
114  hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
115  hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
116  hdma_tx.Init.MemBurst = DMA_MBURST_INC4;
117  hdma_tx.Init.PeriphBurst = DMA_PBURST_INC4;
118 
119  HAL_DMA_Init(&hdma_tx);
120 
121  /* Associate the initialized DMA handle to the UART handle */
122  __HAL_LINKDMA(huart, hdmatx, hdma_tx);
123 
124  /*##-5- Configure the NVIC for DMA #########################################*/
125  /* NVIC configuration for DMA transfer complete interrupt (USARTx_TX) */
126  HAL_NVIC_SetPriority(USARTx_DMA_TX_IRQn, 6, 0);
127  HAL_NVIC_EnableIRQ(USARTx_DMA_TX_IRQn);
128 
129  /*##-6- Enable TIM peripherals Clock #######################################*/
130  TIMx_CLK_ENABLE();
131 
132  /*##-7- Configure the NVIC for TIMx ########################################*/
133  /* Set Interrupt Group Priority */
134  HAL_NVIC_SetPriority(TIMx_IRQn, 6, 0);
135 
136  /* Enable the TIMx global Interrupt */
137  HAL_NVIC_EnableIRQ(TIMx_IRQn);
138 }
139 
148 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
149 {
150  /*##-1- Reset peripherals ##################################################*/
151  USARTx_FORCE_RESET();
152  USARTx_RELEASE_RESET();
153 
154  /*##-2- Disable peripherals and GPIO Clocks ################################*/
155  /* Configure UART Tx as alternate function */
156  HAL_GPIO_DeInit(USARTx_TX_GPIO_PORT, USARTx_TX_PIN);
157  /* Configure UART Rx as alternate function */
158  HAL_GPIO_DeInit(USARTx_RX_GPIO_PORT, USARTx_RX_PIN);
159 
160  /*##-3- Disable the NVIC for UART ##########################################*/
161  HAL_NVIC_DisableIRQ(USARTx_IRQn);
162 
163  /*##-4- Reset TIM peripheral ###############################################*/
164  TIMx_FORCE_RESET();
165  TIMx_RELEASE_RESET();
166 }
167 
176 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/